import App from './App'
import store from './store'
import mixin from '@/common/mixin/mixin'
import http from '@/common/js/http.js'
import share from '@/common/js/share.js'
Vue.prototype.$store = store
Vue.prototype.$http = http
//设置请求前拦截器
http.interceptor.request = (config) => {
	//考虑到安全原因，用户token暂时不放到header里面
	// var userInfo = uni.getStorageSync("userInfo");
	// if (userInfo) {
	// 	//添加通用参数
	// 	config.header = {
	// 		"token": userInfo.token
	// 	}
	// }
}

//设置请求结束后拦截器
http.interceptor.response = (response) => {
	if (response.data.code === -1) {
		uni.showModal({
			content: response.data.message,
			showCancel: false,
			success() {
				uni.navigateBack();
			}
		})
	} else {
		//判断返回状态 执行相应操作
		if (response.data.code === -2) {
			//状态-2代表着用户信息异常，可能被禁用，也可能被删除。
			//移除账户本地状态
			uni.removeStorageSync("userInfo");
			//更新vuex状态
			store.commit('logout');
			uni.showModal({
				content: response.data.message,
				showCancel: false
			})
		} else {
			return response;
		}
	}
}

Vue.mixin(mixin)
Vue.mixin(share)
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif